<template>

	<div class="page">
		<!--<div class="header">· 会员中心 ·</div>-->
		<div class="header-img">
			<div class="member-info">
				<img :src="user.headPortrait"/>
				<div class="info">
					<div class="name">{{user.cnName}}</div>
					<div class="mobile">手机号：{{user.mobile}}</div>
					<div class="mobile">会员等级：{{user.vipLevel}}</div>
				</div>
			</div>
			<div class="member-red-package">
				<div class="member-red-package-item">
					<i class="icon-color iconfont icon-single"></i>
					<span>剩余次数</span>
					<span class="num">{{times}}</span>
				</div>
				<!--<div class="member-red-package-item">
					<i class="icon-color iconfont icon-tubiao-"></i>
					<span>可用红包</span>
					<span class="num">￥{{redPackageAndIntegrals.consume.accessRedpacket}}</span>
				</div>-->
				<div class="member-red-package-item">
					<i class="icon-color iconfont icon-jifen1"></i>
					<span>积分</span>
					<span class="num">{{totalInteger}}</span>
				</div>
				<!--<div class="member-red-package-item">
					<i class="icon-color iconfont icon-hongbao"></i>
					<span>可用红包</span>
					<span class="num">￥22</span>
				</div>-->
			</div>
		</div>
		<div class="member-center-cell" v-for="(item , index) in items" @click="detail(item.to,item.type)">
			<i class="icon-color iconfont" :class="item.icon"></i>
			{{item.title}}
			<i class="icon-color iconfont icon-guanbi" style="position: absolute;right: 0.5rem"></i>
		</div>
	</div>
</template>


<style>
	@import url("member-center.css");
	@import url("../../common/common.css");
</style>
<script>
	import $ from 'jquery'
	import { MessageBox } from 'mint-ui';
	export default{
		name:'register',
		data:function(){
			return {
				items:[],
				openId:null,
				user:{},
				redPackageAndIntegrals:{consume:{accessRedpacket:0},sumIntegral:0},
				times:0,
				totalInteger:0
			}
		},
		created(){
			document.title = '会员中心'
			this.openId = this.utils.getQueryString('openId') || '';
			if(this.utils.state == 'tony'){
				this.items = [
//				{
//					title:'我参与的活动',
//					to:'/activities'+'/',
//					icon:'icon-tubiao-',
//					type:'activity'
//				},{
//					title:'我参与的娱乐活动',
//					to:'/activities'+'/',
//					icon:'icon-tubiao-',
//					type:'activity'
//				},{
//					title:'我参与的旅游活动',
//					to:'/activities'+'/',
//					icon:'icon-tubiao-',
//					type:'activity'
//				},
//				{
//					title:'我的红包',
//					to:'/member-center/redpackage',
//					icon:'icon-hongbao',
//					type:'redpackage'
//				}
//				,
//				{
//					title:'我的积分',
//					to:'/activities'+'/',
//					icon:'icon-jifen1',
//					type:'inter'
//				}
//				,
				{
					title:'充值记录',
					to:'/activities'+'/',
					icon:'icon-single',
					type:'rechange'
				},
				{
					title:'消费记录',
					to:'/activities'+'/',
					icon:'icon-single',
					type:'consume'
				}]
			}else{
				this.items = [{
					title:'我参与的活动',
					to:'/activities'+'/',
					icon:'icon-tubiao-',
					type:'activity'
				},
				{
					title:'我的红包',
					to:'/member-center/redpackage',
					icon:'icon-hongbao',
					type:'redpackage'
				},
				{
					title:'我的积分',
					to:'/activities'+'/',
					icon:'icon-jifen1',
					type:'inter'
				},
				{
					title:'消费记录',
					to:'/activities'+'/',
					icon:'icon-single',
					type:'consume'
				}]
			}
			this.getData();
		},
		methods:{
			getData(){
				var _self = this;
				$.ajax({
				  	type:"post",
				  	contentType:'application/json;charset=UTF-8',
				  	url:this.utils.rootUrl + "fashion/memberInfo",
				  	data:JSON.stringify({
				  		openId:_self.openId
				  	}),
				  	success:function(res){
				  		_self.$Spin.hide();
				  		if(!res.data){
				  			_self.$router.push({ path: '/register/'+_self.openId});
				  			return;
				  		}
				  		_self.user = res.data;
				  		_self.times = res.timesInfo.times;
				  		_self.totalInteger = res.totalInteger;
				  	},
				  	error:function(e){
				  		_self.$Spin.hide();
				  	}
				  });
			},
			getRedPackage(mobile){
				var _self = this;
				$.ajax({
				  	type:"post",
				  	contentType:'application/json;charset=UTF-8',
				  	url:this.utils.rootUrl + "vip/redPackageAndIntegralsNum/"+mobile,
				  	data:JSON.stringify({
				  	}),
				  	success:function(res){
				  		_self.redPackageAndIntegrals = res.data;
				  	},
				  	error:function(e){
				  	}
				  });
			},
			detail(path,type){
				if(type == 'consume' || type == 'rechange'){
					this.$router.push({name:'PurchaseHistory',params:{openId:this.user.openId,type:type}})
					return;
				}
				if(type == 'inter'){
					this.$router.push({name:'memberCenterRedpackage',params:{mobile:this.user.mobile,type:'inter'}})
					return;
				}
				if(type == 'redpackage'){
					this.$router.push({name:'memberCenterRedpackage',params:{mobile:this.user.mobile,type:'redPackage'}})
					return;
				}
				this.$router.push(path+this.utils.getQueryString('openId'));
			}
		}
	}
</script>

